/*
Copyright 2005-2015 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.swing.dings.tester;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.Window;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;

import com.fricano.java42.base.components.utility.impl.Utility;
import com.fricano.java42.base.components.utility.impl.Utility_Swing;
import com.fricano.java42.swing.dings.J42SwingDingController_SlideWindow.Alignment;
import com.fricano.java42.swing.dings.J42SwingDingManager_SlideWindow;
import com.fricano.java42.swing.dings.J42SwingDing_Factory;

final public class J42SwingDing_SlidableTest_03 {

    private static Window  jParentTEST;
    private static JButton jParentB = new JButton("BBBB");
    private static JPanel  jChildTEST;

    static public void main(final String[] args) throws Exception {

        Utility_Swing.setLookAndFeel(Utility_Swing.LookAndFeel.SWING);

        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                jChildTEST = new JPanel() {
                    {
                        final JProgressBar jProgressBar = new JProgressBar();
                        jProgressBar.setSize(396, 96);
                        jProgressBar.setPreferredSize(jProgressBar.getSize());
                        jProgressBar.setIndeterminate(true);
                        jProgressBar.setString("WORKING...WAIT...");
                        jProgressBar.setFont(new Font("System", Font.PLAIN, 28));
                        jProgressBar.setStringPainted(true);
                        setOpaque(false);
                        setSize(396, 110);
                        setBackground(new Color(11, 122, 33, 128));
                        setLayout(new FlowLayout());
                        add(jProgressBar);
                    }
                };

                jParentTEST = new JFrame("MyFrame") {
                    {
                        setSize(640, 480);
                        getContentPane().setBackground(new Color(0, 0, 0, 0));
                        setLocationRelativeTo(null);
                        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                        final Container contentPane = getContentPane();
                        contentPane.setLayout(new GridLayout(2, 11));
                        contentPane.add(jParentB);
                        contentPane.add(new JPanel());
                        setVisible(true);
                    }
                };
            }
        });

        final Component k = ((JFrame) jParentTEST).getGlassPane();

        // --------------------------------------------
        // Create a factory
        // --------------------------------------------
        final J42SwingDing_Factory controller = new J42SwingDing_Factory(jParentTEST);
        // --------------------------------------------
        // Create a slider manager
        // --------------------------------------------
        final J42SwingDingManager_SlideWindow manager = controller.create_SlideManager();

        if (true) {
            manager.attachSlider(Alignment.EXTERIOR_LEFT, jChildTEST, 42, 550, 0, 0);
            for (int x = 0; x != 5; x++) {
                Utility.sleepMilliSeconds(1000);
                manager.slideOpen(true);
                Utility.sleepMilliSeconds(1000);
                manager.slideClosed(true);
                Utility.sleepMilliSeconds(1000);
                if (!manager.isReady()) {
                    break;
                }
            }
            manager.detachSlider(jChildTEST);
            Toolkit.getDefaultToolkit().beep();
        }
    }
}
